#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
typedef unsigned long long ull;
int main() {
    ull a,b,c;
    ull res=1;
    scanf("%lld%lld%lld", &a, &b, &c);
    ull z=a;
    while (b) {
        if (b&1) {
            res*=z;
            res=res%c;
        }
        z=z*z%c;
        b=b>>1;
    }
    cout<<(res)%c<<endl;
    return 0;
}
